package com.web44.ssm.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.logging.Logger;

/**
 * @Title: ServletUtils
 * @Description:
 * @Auther: py
 * @Version: 1.0
 * @create 2023/11/28 21:48
 */
@Component
@Slf4j
public class ServletUtils {

    public static void renderString(HttpServletResponse response,ResponseVo responseVo) throws IOException {
        try {
            response.setStatus(200);
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            String json = JsonUtils.toJson(responseVo);
            response.getWriter().print(json);
        } catch (Exception e) {
            log.error("响应 json 数据失败", e);
        }
    }
}
